package com.camp.socialtong.controller.ajax;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;

import com.camp.socialtong.model.SocialUsersModel;
import com.camp.socialtong.service.DAOSupplyService;
import com.camp.socialtong.service.LoginService;

public class Login extends AbstractCommandController {

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}

	public void setDaoSupplyService(DAOSupplyService daoSupplyService) {
		this.daoSupplyService = daoSupplyService;
	}
	
	DAOSupplyService daoSupplyService;
	LoginService loginService;

	@Override
	protected ModelAndView handle(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		// TODO Auto-generated method stub
		SocialUsersModel socialUsersModel = (SocialUsersModel) command;
		Map<String, Object> resultJson = new HashMap<String, Object>();
		resultJson.put("data", JSONArray.fromObject((ArrayList)loginService.getMyUserInfo(daoSupplyService.getSocialUsersDAO(), socialUsersModel)));
		return new ModelAndView("jsonView", resultJson);
	}

}
